package cn.kgc.controller;

import cn.kgc.bean.pojo.EpStaff;
import cn.kgc.bean.pojo.EqDevice;
import cn.kgc.bean.pojo.StRisk;
import cn.kgc.bean.vo.Result;
import cn.kgc.service.EqDeviceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @projectName: safetyMag
 * @package: cn.kgc.controller
 * @className: EqDeviceController
 * @author: yindexin
 * @description: TODO
 * @date: 2023/5/1 23:41
 * @version: 1.0
 */
@RestController
@RequestMapping("eqDevice")
@Slf4j
public class EqDeviceController {

    @Resource
    private EqDeviceService eqDeviceService;

    @RequestMapping("/getEqDeviceAll/{pageFrom}/{pageSize}")
    private Result getEqDeviceAll(@PathVariable Integer pageFrom,
                                  @PathVariable Integer pageSize){
        PageHelper.startPage(pageFrom, pageSize);
        List<EqDevice> list = eqDeviceService.getEqDeviceAll();
//        int num = 0;
//        for (EqDevice o: list) {
//            num += o.getOverhaul();
//        }
//
//        PageInfo pageInfo = new PageInfo(list);
//        log.info("设备数："+pageInfo.getTotal());
//        log.info("检修次数："+num);
        PageInfo pageInfo = new PageInfo(list);
        return Result.success(pageInfo);

    }
    @RequestMapping("/getCount")
    private Result getCount(){
        List<EqDevice> list = eqDeviceService.getEqDeviceAll();
        int num = 0;
        for (EqDevice o: list) {
            num += o.getOverhaul();
        }

        PageInfo pageInfo = new PageInfo(list);
        log.info("设备数："+pageInfo.getTotal());
        log.info("检修次数："+num);
        return Result.success(num);
    }


    @RequestMapping("/addEqDeviceAll")
    private Result addEqDeviceAll(@RequestBody EqDevice eqDevice){
        log.info(eqDevice.toString());
        boolean flag = eqDeviceService.addEqDeviceAll(eqDevice);
        if (flag) {
        return Result.success();
        }
        return Result.failure();
    }
    @RequestMapping("/deletEqDeviceAllById/{id}")
    private Result deletEqDeviceAllById(@PathVariable Integer id){
        boolean flag = eqDeviceService.deletEqDeviceAllById(id);
        if (flag) {
            return Result.success();
        }
        return Result.failure();
    }
    @RequestMapping("/UpdateEqDeviceAll")
    private Result UpdateEqDeviceAll(@RequestBody EqDevice eqDevice){
        boolean flag = eqDeviceService.UpdateEqDeviceAll(eqDevice);
        if (flag) {
            return Result.success();
        }
        return Result.failure();
    }
}
